package com.gjy.design.strategy.en;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-06 11:18:52
 */
public enum Operation {
    // 加法策略
    PLUS {
        @Override
        public double apply(double x, double y) {
            return x + y;
        }
    },
    // 减法策略
    MINUS {
        @Override
        public double apply(double x, double y) {
            return x - y;
        }
    },
    // 乘法策略
    TIMES {
        @Override
        public double apply(double x, double y) {
            return x * y;
        }
    },
    // 除法策略
    DIVIDE {
        @Override
        public double apply(double x, double y) {
            if (y == 0) {
                throw new ArithmeticException("除数不能为零！");
            }
            return x / y;
        }
    };

    // 抽象方法，每个枚举实例都必须实现
    public abstract double apply(double x, double y);
}
